<?php

namespace Admin\Controller;

class AnswerController extends CommonController
{
    /** 回答列表 */
    public function lists()
    {
        $key     = I('request.key', '', 'trim');
        $optimal = I('request.optimal', '', 'trim');
        $sort    = 'id DESC';

        $map = array();
        if ($key) {
            $key_type = I('request.key_type', 0, 'intval');
            if ($key_type == '1') {
                $map['content'] = array('like', '%' . $key . '%');
            }
            if ($key_type == '2') {
                $map['uid'] = intval($key);
            }
        }
        if ($optimal <> '') {
            $map['optimal'] = intval($optimal);
        }

        $list = D('Answer')->get_list($map, true, $sort, 10);

        $this->assign('lists', $list);

        $this->display();
    }

    /** 删除问题 */
    public function delete()
    {
        $ids = I('request.id');

        $ret = D('Answer')->del_answer($ids);
        if ($ret['status'] === false) {
            $this->error($ret['content']);
        }

        $this->success("成功删除{$ret['count']}条数据");
    }
}